package com.apexedu.lbwsclient;


import com.apexedu.lbwsclient.business.LbRecord;
import com.apexedu.lbwsclient.business.WorkflowProfile;
import com.apexedu.lbwsclient.document.Document;
import com.apexedu.lbwsclient.document.DocumentEntry;
import com.apexedu.util.FileUtil;

import javax.activation.DataHandler;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * Created by ys on 2015/7/3.
 */
public class Test {

    public static void main(String[] args) {
        testQueryWorkflowDescribe();
    }

    public static void testDownload(){

        List<DocumentEntry> documentEntries = LiveBosWebServiceUtils.queryDocumentEntry("V_OA_SendDocument_NJCI_V3", "GDFJ", "937");
        documentEntries.get(0).getFilename();

        Document document = LiveBosWebServiceUtils.getDocumentFile("V_OA_SendDocument_NJCI_V3", "GDFJ", "937", "2");
        String fileName = document.getFilename();
        long length = document.getLength();
        DataHandler dataHandler = document.getDocumentData();
        String contentType = dataHandler.getContentType();
        System.out.println("文件名："+fileName);
        System.out.println("类型："+contentType);
        System.out.println("长度："+length);
        try {
            InputStream inputStream = dataHandler.getInputStream();
            FileUtil.saveFile(inputStream, "", fileName, fileName);
            if(inputStream!=null){
                inputStream.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void testQuery(){
        //流程执行步骤
        List<LbRecord> lbRecords = LiveBosWebServiceUtils.query("WO_BMFW");
        System.out.println("size>>>counts==="+lbRecords.size() );
        for(LbRecord lbRecord : lbRecords){
            System.out.println("size>>>count==="+lbRecord.getSize() );
            for(String s : lbRecord.getStrings()){

                System.out.println(">>>"+s );
            }
            for(Object s : lbRecord.getValues()){

                System.out.println(">>>--"+s );
                System.out.println("-----" );
            }
            System.out.println("-----------------------------------------" );
        }
    }

    public static void testQueryTasks(){
        //流程执行步骤
        List<LbRecord> lbRecords = LiveBosWebServiceUtils.queryTasks("4213");
        for(LbRecord lbRecord : lbRecords){
            System.out.println("size>>>"+lbRecord.getSize() );
            for(String s : lbRecord.getStrings()){

                System.out.println(">>>"+s );
            }
            for(Object s : lbRecord.getValues()){

                System.out.println(">>>--"+s );
            }
        }
    }

    public static void test3(){
        //流程执行步骤
        List<LbRecord> lbRecords = LiveBosWebServiceUtils.queryWorkStepDetail(257);
        for(LbRecord lbRecord : lbRecords){
            System.out.println("size>>>"+lbRecord.getSize() );
            for(String s : lbRecord.getStrings()){

                System.out.println(">>>"+s );
            }
            for(Object s : lbRecord.getValues()){

                System.out.println(">>>--"+s );
            }
        }
    }

    public static void testQueryWorkflowDescribe(){
        List<WorkflowProfile> workflowProfiles = LiveBosWebServiceUtils.queryWorkflowDescribeByOwner("4213");
        for(WorkflowProfile workflowProfile : workflowProfiles){
            System.out.println(workflowProfile.getName() + "====="+ workflowProfile.getDescribe());
            System.out.println(workflowProfile.getAttribute() + "====="+ workflowProfile.getType());
            System.out.println(workflowProfile.getCategory() + "====="+ workflowProfile.getI18NDescribe());
        }
    }
}
